/**
 * 
 */
package me.myachievements.web.account;

import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.apache.wicket.validation.validator.EmailAddressValidator;
import org.apache.wicket.validation.validator.StringValidator;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;

import me.myachievements.persistence.account.Account;
import me.myachievements.persistence.account.AccountPersistenceManager;

/**
 * @author besseym
 *
 */
public abstract class AccountForm extends Form<Account> {
	
	@SpringBean(name="accountPersistenceManager")
	AccountPersistenceManager accountPersistenceManager;
	
	/**
	 * Constructor
	 * @param id
	 * @param legend
	 * @param account
	 */
	public AccountForm(String id, String legend, Account account){
		super(id, new CompoundPropertyModel<Account>(account));
		
		addComponents(legend);
	}
	
	/**
	 * Constructor
	 * @param id
	 * @param legend
	 * @param iModel
	 */
	public AccountForm(String id, String legend, IModel<Account> iModel){
		super(id, new CompoundPropertyModel<Account>(iModel));
		
		addComponents(legend);
	}
	
	/**
	 * Add Form components
	 */
	private void addComponents(String legend){
		
		add(new Label("form_legend", legend));
		add(new TextField<String>("username").setRequired(true).add(StringValidator.maximumLength(50)));
		add(new TextField<String>("name").setRequired(true).add(StringValidator.maximumLength(50)));
		add(new TextField<String>("email").setRequired(true).add(StringValidator.maximumLength(100)).add(EmailAddressValidator.getInstance()));
	}

}
